import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../pages/Login'
import forget from '../pages/Login/forget.vue'
import Home from '../pages'

import FoodCenter from '../pages/FoodCenter'
import TableCenter from '../pages/TableCenter'
import MangCenter from '../pages/MangCenter'
import MessageCenter from '../pages/MessageCenter'
import Register from '../pages/Login/Register.vue'
import UserCenter from '../pages/UserCenter'
import OrderList from '../pages/OrderCenter/OrderList'
import OldOrderList from '../pages/OrderCenter/OldOrderList'


Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: login },
  { path: '/forget', component: forget },
  { path: '/Register', component: Register },
  {
    path: '/home',
    component: Home,
    redirect: '/OrderList',
    children: [
      { path: '/FoodCenter', component: FoodCenter },
      { path: '/OrderList', component: OrderList },
      { path: '/OldOrderList', component: OldOrderList },
      { path: '/TableCenter', component: TableCenter },
      { path: '/MangCenter', component: MangCenter },
      { path: '/MessageCenter', component: MessageCenter },
      { path: '/UserCenter', component: UserCenter },
    ]
  }
]
const router = new VueRouter({
  routes
})

// // 添加全局前置导航守卫
// router.beforeEach((to, from, next) => {
//   // 先判断token存不存在
//   const token = localStorage.get('token')
//   // token不存在，说明当前用户是未登录，应该跳转至登录页面
//   // 如果token一开始就不存在，而且所在的页面就是登录页面

//   if(!token && to.path !== '/login'){
//     next('/login')
//   }else if(token ) {  // token存在说明，已经登录了，此时跳转首页、
//     // 已经登陆了就不能再次去登录页面了
//     if(to.path === '/login'){
//       next('/home')
//     }else{
//       next()
//     } 
//   }else{
//     next('/login')
//   }
// })


export default router
